package com.exam.api.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisOperations;


/**
 * @Author bcheng
 * @Create 2024/1/13 12:09
 * @Description Redisson配置类
 */
@Slf4j
@Configuration
@ConditionalOnClass({Redisson.class, RedisOperations.class})
public class RedissonConfig {

    @Resource
    @Lazy
    private ObjectMapper objectMapper;

    @Bean
    public RedissonAutoConfigurationCustomizer redissonAutoConfigurationCustomizer() {
        return configuration -> {
            log.info(" <<<=== Redisson 使用 JsonJacksonCodec");
            configuration.setCodec(new JsonJacksonCodec(objectMapper));
        };
    }
}
